﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace UI
{
     public partial class ManterPrograma : System.Web.UI.Page
    {
        private bool bNovo = false;

        private void LimparCampos()
        {
            TxId.Text = "";
            TxNome.Text = "";
            TxDuracao.Text = "";
            TxSinopse.Text = "";
            DdTema.SelectedIndex = 0;
        }
   
     
        protected void BtNovoPrograma_Click(object sender, EventArgs e)
        {
                   LimparCampos();
            txtNumero.Focus();
            bNovo = ((Button)(sender)).Text == "Novo Programa";
            if (bNovo)
            {
                lbStatus.Text = "Modo Inserção";
        }
    }



         protected void BtGravar_Click(object sender, EventArgs e)
         {
         
            if (lbStatus.Text == "Modo Inserção")
            {
                Negocios.ProgramaBOMetodos programa = new Negocios.ProgramaBOMetodos();
                ProgramaBO can = new ProgramaBO();
                Pro.Nome = txtNome.Text;
                Pro.Descricao = txtDescrição.Text;
                Pro.Tematica = Convert.ToInt32(DdTema.SelectedValue);
                programa.Insere(pro);
                
                    GridView1.DataBind();

            }
            else // update
            {
                Negocios.ProgramaBOMetodos programa = new Negocios.ProgramaBOMetodos();
                ProgramaBO can = new ProgramaBO();
                pro.Id = Convert.ToInt32(txtNumero.Text);
                pro.Nome  = TxNome.Text;
                pro.Descricao = txtDescrição.Text;
                pro.Tematica = Convert.ToInt32(DdTema.SelectedValue);
                programa.Atualizar(can);
                
                    GridView1.DataBind();
                
                canal = null;
            }
            lbStatus.Text = "";
        }

         protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
         {
         
         }

         




         protected void txtNumero_TextChanged(object sender, EventArgs e)
         {

         }

        

         protected void Page_Load(object sender, EventArgs e)
         {

         }

         protected void lbRemover_Click(object sender, EventArgs e)
         {
             Negocios.ProgramaBOMetodos programa = new Negocios.ProgramaBOMetodos();
             ProgramaBO can = new ProgramaBO();
             pro.Id = Convert.ToInt32(txtNumero.Text);
             programa.Excluir(pro);

             GridView1.DataBind();
         }

         protected void LbAtualizar_Click(object sender, EventArgs e)
         {
             LinkButton lb = (LinkButton)sender;
             DataControlFieldCell celula = (DataControlFieldCell)lb.Parent;
             GridViewRow linha = (GridViewRow)celula.Parent;
             int ID = Convert.ToInt32(linha.Cells[0].Text);
             ProgramaBOMetodos pBOM = new ProgramaBOMetodos();
             ProgramaBO pBO = pBOM.Consultar(ID);

             Nome.Text = pBO.Nome;
             Duracao.Text = pBO.Duracao;
             cbTema = pBO.Tema;
             Sinopse.Text = pBO.Sinopse;
             GridView1.DataBind();
         }
    }
 }